package com.ternnetwork.batch.quartz.trigger;

import java.util.HashMap;
import java.util.Map;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
import com.ternnetwork.batch.quartz.job.TestUserLauncherJob;


/**
 * 配置作业触发器
 * 
 * @author xuwenfeng
 *
 */
@Configuration
public class TestUserJobTriggerConfiguration {
	
	
	/**
	 * JobDetailFactoryBean配置
	 * @return
	 */
	@Bean
	public JobDetailFactoryBean jobDetailFactoryBean(){
		JobDetailFactoryBean jobFactory = new JobDetailFactoryBean();
		jobFactory.setJobClass(TestUserLauncherJob.class);
		jobFactory.setGroup("test_user_group");
		jobFactory.setName("test_user_job");
		Map<String, Object> map = new HashMap<>(2);
		
		jobFactory.setJobDataAsMap(map);
		return jobFactory;
	}
	
	
	/**
	 * 配置触发器
	 * @return
	 */
	@Bean("testCronTriggerFactoryBean")
	public CronTriggerFactoryBean cronTriggerFactoryBean(){
		CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean();
		cronTriggerFactoryBean.setJobDetail(jobDetailFactoryBean().getObject());
		cronTriggerFactoryBean.setStartDelay(5000);
		cronTriggerFactoryBean.setName("test_user_trigger");
		cronTriggerFactoryBean.setGroup("test_user_trigger_group");
		//每间隔5s触发一次Job任务
		cronTriggerFactoryBean.setCronExpression("0/50 * * * * ? ");
		return cronTriggerFactoryBean;
	}
	

}
